package com.iRomantic.domain.entity;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

import com.iRomantic.config.Constant;
import com.jfinal.plugin.activerecord.Model;

/**
 * 婚庆企业
 * @author serenity
 *
 */
public class Enterprise extends Model<Enterprise> {

	private static final long serialVersionUID = -3951035472254460001L;
	
	public static final Enterprise DAO = new Enterprise();
	
	public boolean save(){
		Timestamp currTime = new Timestamp(System.currentTimeMillis());
		if(this.getStr("id")!=null){
			this.set("id", UUID.randomUUID().toString());
		}
		this.set("regist", currTime);
		this.set("createTime", currTime);
		return super.save();
	}
	
	public void setOSSPath(Enterprise enterprise){
		if(null!=enterprise.getStr("picture")){
			enterprise.set("picture", Constant.OSS_PATH+Constant.ENTERPRISE_PICTURE +this.getStr("id")+"/" +enterprise.getStr("picture"));
		}
	}
	
	/**
	 *查询该企业下的客户
	 */
	public List<Client> getClients(String name,String id)
	{
		System.out.println(this.get("id"));
		//String []values=new String[]{this.get("id"),name,id};   
		return  Client.DAO.find("select t.* from t_client t where t.t_c_e=? or t.name like ? or t.id like ? " 
				,this.get("id"),name,id);
		//Client.DAO.
		
	}
	

}
